@extends('admin.common.base-master')

@section('html-head')
    {{--<link href="{{url('/vendor/tyupload/control/css/zyUpload.css')}}" type="text/css" rel="stylesheet" />--}}
    <link href="{{url('css/jquery.form.css')}}" type="text/css" rel="stylesheet" />
    {{--<script src="{{url('/vendor/My97DatePicker/WdatePicker.js')}}"></script>--}}
    <script src="{{url('/js/lib/jquery.form.js')}}"></script>
    <style>
        .btn_add_classify{
            background: #31bcd3;margin-left:10px;height: 5px;width: 50px;color: white;text-align: center;padding:5px;border-radius:7px;box-shadow: 3px 2px 9px #888888;
        }
    </style>
@endsection

@section('html-body')
    <!-- content start -->
    <div id="content">
        <!-- cur-position start -->
        <div id="cur-position">
            <span class="tit">当前位置：</span>
            <a href="#">行业管理</a>
            <em></em>
            <a href="{{route('Admin.Home.jobTypeList')}}">职业分类列表</a>
            <em>></em>
            <a href="#">职业分类设置</a>
        </div>
        <!-- cur-position end -->

        <!-- 二级目录 -->
        @include('admin.common.trade-header')

        <div class="gg-step">
            <form  id="advform">
                <input type="hidden" name="id" id="jobtypeid" value="@if($jobType){{$jobType->id}}@endif"/>
                <div class="gg-list">
                    <label class="tit">职位名称</label>
                    <div class="cont">
                        <input class="gg-ipt" type="text" placeholder="请输入职位名称" name="name" id="name" value="@if($jobType){{$jobType->name}}@endif" /><cite id="title_re" class="required">*</cite>
                        <p class="text">可输入2-40个字符（一个汉字等于2个字符）</p>
                    </div>
                </div>

                <div class="gg-list">
                    <label class="tit">所属行业</label>
                    <div class="cont">
                        <select name="trade" id="trade">
                            @if(count($trades) > 0)
                                @foreach($trades as $trade)
                                    <option value="{{$trade->id}}" @if($jobType && $jobType->trade_id == $trade->id)selected @endif>{{$trade->name}}</option>
                                @endforeach
                            @endif
                        </select>
                    </div>
                </div>

            </form>
            <div class="gg-list" >
                <label class="tit">&nbsp;</label>
                <div class="cont" >
                    <a href="javascript:;" class="next-step" id="btn-set">提交</a>
                </div>
            </div>
        </div>
    </div>

    <!-- content end -->
    <script>
        $(function() {
            $(document).on('click', '#btn-set', function () {
                var name = $('#name').val();
                var trade  = $('#trade option:selected').val();
                var id = $('#jobtypeid').val();

                $.ajax({
                    url: '{{route("Api.Admin.sys.addJobType")}}',
                    type: 'post',
                    dataType: 'json',
                    data: {
                        name: name,
                        trade:trade,
                        id:id
                    },
                    success: function (obj) {
                        if (obj.level == "success") {
                            noty({
                                text: obj.message, type: obj.level, timeout: 600,
                                callback: {
                                    afterClose:function(){
                                        window.location.href = "{{route('Admin.Home.jobTypeList')}}";
                                    }
                                }
                            });
                        } else if (obj.level == "error") {
                            noty({text: obj.message, type: obj.level, timeout: 600});
                        }

                    },
                    error: function (obj) {
                        console.log(obj);
                    }
                });
            });
        });
    </script>
@endsection